package com.fili.params;

import static java.lang.Float.*;
import static java.lang.Integer.*;

/**
 * Date: Oct 30, 2005
 * Time: 2:28:47 PM
 *
 * @author Claudiu-Florin FILIMON for Borux Consulting S.R.L.
 */
public class Param implements Comparable
{
	private String paramName;
	private Object currentValue;
	private Object minValue;
	private Object maxValue;
/*-------------------------------------------------------------------------------------
    Getters and setters
 --------------------------------------------------------------------------------------*/

	public String getParamName()
	{
		return paramName;
	}

	public void setParamName(String paramName)
	{
		this.paramName = paramName;
	}

	public Object getCurrentValue()
	{
		return currentValue;
	}

	public void setCurrentValue(Object currentValue)
	{
		this.currentValue = currentValue;
	}

	public Object getMinValue()
	{
		return minValue;
	}

	public void setMinValue(Object minValue)
	{
		this.minValue = minValue;
	}

	public Object getMaxValue()
	{
		return maxValue;
	}

	public void setMaxValue(Object maxValue)
	{
		this.maxValue = maxValue;
	}

/*-------------------------------------------------------------------------------------
	Constructors
 --------------------------------------------------------------------------------------*/

	public Param(String paramName, Object currentValue, Object minValue, Object maxValue)
	{
		this.paramName = paramName;
		this.currentValue = currentValue;
		this.minValue = minValue;
		this.maxValue = maxValue;
	}

	public Param(String paramName, Object currentValue)
	{
		this.paramName = paramName;
		this.currentValue = currentValue;
	}

	public Param(String paramName, String type, String currentValue, String minValue, String maxValue)
	{
		setValues(paramName, type, currentValue, minValue, maxValue);
	}
/*-------------------------------------------------------------------------------------
	Methods
 --------------------------------------------------------------------------------------*/

	public String getParamType()
	{
		return currentValue.getClass().getSimpleName();
	}

	public void setValues(String paramName, String type, String currentValue, String minValue, String maxValue)
	{
		this.paramName = paramName;
		if (type.equals(Integer.class.getSimpleName()))
		{
			this.currentValue = parseInt(currentValue);
			if (minValue != null)
				this.minValue = parseInt(minValue);
			if (maxValue != null)
				this.maxValue = parseInt(maxValue);
			return;
		}
		if (type.equals(Float.class.getSimpleName()))
		{
			this.currentValue = parseFloat(currentValue);
			if (minValue != null)
				this.minValue = parseFloat(minValue);
			if (maxValue != null)
				this.maxValue = parseFloat(maxValue);
			return;
		}
		if (type.equals(Long.class.getSimpleName()))
		{
			this.currentValue = Long.parseLong(currentValue);
			if (minValue != null)
				this.minValue = Long.parseLong(minValue);
			if (maxValue != null)
				this.maxValue = Long.parseLong(maxValue);
			return;
		}
		if (type.equals(Double.class.getSimpleName()))
		{
			this.currentValue = Double.parseDouble(currentValue);
			if (minValue != null)
				this.minValue = Double.parseDouble(minValue);
			if (maxValue != null)
				this.maxValue = Double.parseDouble(maxValue);
			return;
		}
		if (type.equals(Boolean.class.getSimpleName()))
		{
			this.currentValue = Boolean.parseBoolean(currentValue);
			if (minValue != null)
				this.minValue = Boolean.parseBoolean(minValue);
			if (maxValue != null)
				this.maxValue = Boolean.parseBoolean(maxValue);
			return;
		}
		if (type.equals(String.class.getSimpleName()))
		{
			this.currentValue = currentValue;
			this.minValue = minValue;
			this.maxValue = maxValue;
			return;
		}
		if (type.equals(ListParam.class.getSimpleName()))
		{
			this.currentValue = new ListParam(ListParam.parseList(currentValue));
			if (minValue != null)
				this.minValue = new ListParam(ListParam.parseList(minValue));
			if (maxValue != null)
				this.maxValue = new ListParam(ListParam.parseList(maxValue));
			return;
		}
	}
/*-------------------------------------------------------------------------------------
    Overrides
 --------------------------------------------------------------------------------------*/

/*-------------------------------------------------------------------------------------
    Implementations
 --------------------------------------------------------------------------------------*/

	public int compareTo(Object o)
	{
		Param p = (Param)o;

		return paramName.toUpperCase().compareTo(p.paramName.toUpperCase());
	}
}
